import Shop from '../../api/shop';
import Product from '@/api/product';

const state = {
  shopData: [], // 店铺列表
  shopSelectData: [], // 店铺列表--选择店铺
  templateData: [], // 模板列表
};

const mutations = {
  // 1.店铺列表
  setShopList(state, list) {
    state.shopSelectData = list;
  },
  // 2.模板列表
  setTemplateList(state, list) {
    state.templateData = list;
  },
};

const actions = {
  // 1.获取店铺列表
  productStoreList({ state, commit }, param = {}) {
    if (state.shopSelectData.length) return;
    Shop.getShopList(param)
      .then((result) => {
        if (result.code == 200) {
          commit('setShopList', result.data.rows);
        }
      })
      .catch((err) => {});
  },

  // 2.获取模板列表
  productTemplateList({ state, commit }, param = {}) {
    Product.getProductTemplateList().then((res) => {
      if (res.code == 200) {
        commit('setTemplateList', res.data.rows);
      }
    });
  },
};

const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
